import request from "@/utils/request";

//登录接口
export function login(data) {
  return request({
    method: "post",
    url: "/login",
    data,
  });
}

//获取首页列表
export function getLIst() {
  return request({
    method: "get",
    url: "/menus",
  });
}

//获取管理员列表
export function getUser(params) {
  return request({
    method: "get",
    url: "/users",
    params,
  });
}

//添加管理员
export function addUser(data) {
  return request({
    method: "post",
    url: "/users",
    data,
  });
}

//删除管理员
export function delUser(id) {
  return request({
    method: "DELETE",
    url: `/users/${id}`,
  });
}

//获取单个用户信息
export function getOneUser(id) {
  return request({
    method: "GET",
    url: `/users/${id}`,
  });
}

//编辑用户信息
export function editUser(data) {
  return request({
    method: "PUT",
    url: `/users/${data.id}`,
    data,
  });
}

//获取角色
export function getRole() {
  return request({
    method: "GET",
    url: `/roles`,
  });
}

//设置用户角色
export function setRole(data) {
  return request({
    method: "PUT",
    url: `/users/${data.id}/role`,
    data: {
      rid: data.role,
    },
  });
}

//搜索
export function search(params) {
  return request({
    method: "get",
    url: `/users`,
    params,
  });
}
//编辑状态
export function changeState(params) {
  return request({
    method: "PUT",
    url: `/users/${params.id}/state/${params.mg_state}`,
  });
}

//获取权限列表

export function getRightsList() {
  return request({
    method: "get",
    url: `/rights/list`,
  });
}

//获取权限列表
export function getRight() {
  return request({
    method: "get",
    url: `/rights/tree`,
  });
}

//添加权限
export function putRoles(id, b) {
  return request({
    method: "POST",
    url: `/roles/${id}/rights`,
    data: {
      rids: b,
    },
  });
}

//删除权限
export function delRight(data) {
  return request({
    method: "DELETE",
    url: `/roles/${data.id}/rights/${data.id1}`,
  });
}
//获取角色列表
export function getRoleList() {
  return request({
    method: "get",
    url: `/roles`,
  });
}

//添加角色
export function pushRole(data) {
  return request({
    method: "post",
    url: `/roles`,
    data,
  });
}

//删除角色
export function delRole(id) {
  return request({
    method: "DELETE",
    url: `/roles/${id}`,
  });
}

//获取单个角色
export function getOneRole(id) {
  return request({
    method: "get",
    url: `/roles/${id}`,
  });
}

//编辑单个角色
export function editRole(data) {
  return request({
    method: "put",
    url: `/roles/${data.roleId}`,
    data,
  });
}
